package com.springboot_nanhua4.configs;


import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 阿里云OSS配置类
 * 用于配置并初始化OSS客户端，以便在项目中操作阿里云对象存储服务
 */
@Configuration
@Data
@ConfigurationProperties(prefix = "oss")
public class OssConfig {

    /** OSS服务端点 */
    private String endpoint;

    /** 访问密钥ID */
    private String accessKeyId;

    /** 访问密钥秘钥 */
    private String accessKeySecret;

    /** 存储桶名称 */
    private String bucketName;

    /** 访问URL前缀 */
    private String urlPrefix;

    /**
     * 构建OSS客户端并注入Spring容器
     * @return OSS客户端实例
     */
    @Bean
    public OSS ossClient() {
        return new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
    }
}